package uiux4.helloandroid;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void main_activity(View view) {
    	setContentView(R.layout.activity_main);
    }
    
    public void layout2(View view) {
    	setContentView(R.layout.layout02);
    }
    
    public void layout3(View view) {
    	setContentView(R.layout.layout03);
    }
    
    public void layout4(View view) {
    	setContentView(R.layout.layout04);
    	
    	Button inputBtn = (Button)findViewById(R.id.inputBtn);
    	Button cancelBtn = (Button)findViewById(R.id.cancelBtn);
    	Button goMenu = (Button)findViewById(R.id.goMenu);
    	
    	inputBtn.setOnClickListener(this);
    	cancelBtn.setOnClickListener(this);
    	goMenu.setOnClickListener(this);

    }
    
    public void layout5(View view) {
    	setContentView(R.layout.layout05);
    }
    
    public void changeActivity(View view) {
    	Intent intent = new Intent(this, SubActivity.class);
    	startActivity(intent);
    	// 반환 값이 필요한 경우 >>> startActivityForResult(intent, requestCode); 
    }
    
    @Override
    public void onClick(View view) {
    	int id = view.getId();
    	switch(id) {
    	case R.id.inputBtn:
    		String mid = ((EditText)findViewById(R.id.mid)).getText().toString();
    		String pwd = ((EditText)findViewById(R.id.pwd)).getText().toString();
    		String irum = ((EditText)findViewById(R.id.irum)).getText().toString();
    		String phone = ((EditText)findViewById(R.id.phone)).getText().toString();
    		String email = ((EditText)findViewById(R.id.email)).getText().toString();
    		
    		if(mid.equals("")) {
    			findViewById(R.id.mid).requestFocus();
    			Toast.makeText(getApplicationContext(), "아이디가...", Toast.LENGTH_SHORT).show();
    		} else if(pwd.equals("")) {
    			findViewById(R.id.pwd).requestFocus();
    			Toast.makeText(getApplicationContext(), "암호가...", Toast.LENGTH_SHORT).show();
    		} else if(irum.equals("")) {
    			findViewById(R.id.irum).requestFocus();
    			Toast.makeText(getApplicationContext(), "이름이...", Toast.LENGTH_SHORT).show();
    		} else if(phone.equals("")) {
    			findViewById(R.id.phone).requestFocus();
    			Toast.makeText(getApplicationContext(), "연락처가...", Toast.LENGTH_SHORT).show();
    		} else if(email.equals("")) {
    			findViewById(R.id.email).requestFocus();
    			Toast.makeText(getApplicationContext(), "이 메일이...", Toast.LENGTH_SHORT).show();
    		} else {
    			Toast.makeText(getApplicationContext(), "모두 입력하셨습니다.", Toast.LENGTH_SHORT).show();
    		}
    		break;	
    	case R.id.cancelBtn: Toast.makeText(getApplicationContext(), "취소됨", Toast.LENGTH_SHORT).show();
    		break;
    	case R.id.goMenu: setContentView(R.layout.activity_main);
    		break;
    	}
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
